package com.qipay.mapper;

import com.qipay.baas.model.Sp;
import com.qipay.baas.model.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
@Mapper
public interface UserMapper extends com.qipay.baas.mapper.UserMapper {

    @Select({"SELECT * FROM user WHERE name = #{userName}"})
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="sex", property="sex", jdbcType=JdbcType.TINYINT),
            @Result(column="pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="icon", property="icon", jdbcType=JdbcType.VARCHAR),
            @Result(column="pid", property="pid", jdbcType=JdbcType.INTEGER),
            @Result(column="level", property="level", jdbcType=JdbcType.INTEGER),
            @Result(column="auth_code", property="authCode", jdbcType=JdbcType.VARCHAR)
    })
    User findFirstByName(@Param("userName") String userName);

    @Select({"select * from user where name like concat('%',#{name},'%') limit #{offset}, #{size}"})
    List<User> page(@Param("name") String name, @Param("offset") int offset, @Param("size") int size);

    @Select({"select count(id) from user where name like concat('%',#{name},'%')"})
    long countAll(@Param("name") String name);

    @Delete({
            "delete from user",
            "where name = #{name,jdbcType=VARCHAR}"
    })
    int deleteByName(String name);
}